#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>

#include "log.h"
#include "bloom.h"


int main(int argc, char **argv)
{
	int same = 0;
	PBloom p_bloom = (PBloom)malloc(sizeof(Bloom));
	int ret = init_bloom(p_bloom, 10000000, 0.0001);
	if(ret==SIZE_OVERFLOW_ERROR)
	{
		write_log(LOG_WARNING, NULL, "%s\n", "overflow");
		return -1;
	}

	FILE *fd = fopen("./indata.bl", "r");
	if(fd==NULL)
	{
		printf("open file error!\n");
		return -1;
	}

	char buf[32] = {0};
	while(1)
	{
		memset((void*)buf, 0x00, 32);
		if(!fgets(buf, 32, fd))
			break;
		add_ele(p_bloom, buf);
	}

	fclose(fd);
	fd = fopen("./indata2.bl", "r");
	if(fd==NULL)
	{
		printf("open file error!\n");
		return -1;
	}

	while(1)
	{
		memset((void*)buf, 0x00, 32);
		if(!fgets(buf, 32, fd))
			break;

		if(check_ele(p_bloom, buf)==EXIST)
		{
			same++;
			printf("The same str:%s\n", buf);
		}
	}
	printf("same:%d\n", same);

	getchar();

	destroy_bloom(p_bloom);	
	return 0;
}
